package com.manager.devicemanager.util;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;

import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CodeGenerator {


    public static void main(String[] args) {



        String schemaName = "public";
       //FastAutoGenerator.create("jdbc:postgresql://localhost:5432/icboardata1??currentSchema="+schemaName, "postgres", "postgres")
//        FastAutoGenerator.create("jdbc:postgresql://localhost:5432/icboardconfig??currentSchema="+schemaName, "postgres", "postgres")
//        FastAutoGenerator.create("jdbc:postgresql://localhost:5432/pdboardata1??currentSchema="+schemaName, "postgres", "postgres")
        FastAutoGenerator.create("jdbc:postgresql://8.136.3.207:5432/icboardrealtimedata?currentSchema="+schemaName, "postgres", "Abcdef123456")
                .globalConfig(builder -> {
                    builder.author("wpf") // 设置作者
                            .outputDir("src/main/java");
                    builder.disableOpenDir();
                    builder.dateType(DateType.ONLY_DATE);
                })
                .packageConfig(builder -> {
                    builder.parent("com.manager.devicemanager")// 设置父包名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "src/main/resources/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
//                    builder.addTablePrefix("t_", "c_"); // 设置过滤表前缀

//                    builder.addInclude("autotest","board_1","board_template","bramtest","component_1","component_template","manualtest","status_1","status_template"); // 设置需要生成的表
//                    builder.addInclude("testlog","testcase","testbatch","statuscodeinformation","devicestatus"); // 设置需要生成的表
//                    builder.addInclude("real_time_board_template","real_time_component_template","real_time_status_template"); // 设置需要生成的表
                    builder.addInclude("cramtest"); // 设置需要生成的表
                    builder.addInclude("manualtest");
                    builder.entityBuilder().enableLombok().enableFileOverride();
                    builder.controllerBuilder().enableRestStyle().enableFileOverride();
                    builder.serviceBuilder().enableFileOverride();
                    builder.mapperBuilder().enableFileOverride();
                    builder.entityBuilder().enableFileOverride();

                })
               .injectionConfig(builder -> {
                   builder.customMap(Collections.singletonMap("swagger2", true));
                   builder.customMap(Collections.singletonMap("schemaName", schemaName));
               })
               .templateConfig(builder -> {
                   // 使用自定义模板
                   builder.controller("templates/myController.java")
                           .service("templates/myService.java")
                           .serviceImpl("templates/myServiceImpl.java")
                           .entity("templates/myEntity.java")
                           .mapper("templates/myMapper.java")
                           .xml("templates/myMapper.xml");
//                   builder.service("templates/myService.java")
//                           .serviceImpl("templates/myServiceImpl.java")
//                           .entity("templates/myEntity.java")
//                           .mapper("templates/myMapper.java")
//                           .xml("templates/myMapper.xml");
               })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();


    }
}